package com.example.portlocalforward.entity;

import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 端口本地转发实体类
 * 
 * @author Generated
 * @version 1.0.0
 */
@Entity
@Table(name = "port_local_forward")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PortLocalForward {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "name", nullable = false, length = 100)
    private String name; // 转发名称

    @Column(name = "ssh_tunnel_id", nullable = false)
    private Long sshTunnelId; // SSH隧道ID（外键）

    @Column(name = "local_port", nullable = false)
    private int localPort; // 本地端口

    @Column(name = "remote_host", nullable = false, length = 255)
    private String remoteHost; // 远程主机

    @Column(name = "remote_port", nullable = false)
    private int remotePort; // 远程端口

    @Column(name = "url", length = 255)
    private String url; // 访问地址

    @Column(name = "tags", length = 500)
    private String tags; // 标签，多个标签用逗号分割

    @Column(name = "created_time", nullable = false)
    private LocalDateTime createdTime; // 创建时间

    @Column(name = "updated_time")
    private LocalDateTime updatedTime; // 更新时间

    @PrePersist
    protected void onCreate() {
        createdTime = LocalDateTime.now();
        updatedTime = LocalDateTime.now();
    }

    @PreUpdate
    protected void onUpdate() {
        updatedTime = LocalDateTime.now();
    }
}
